package com.ll.tankgame;

/**
 * @author liubw
 * @date 2024/6/25 0025
 */
public class Shot implements Runnable{
    private int x;
    private int y;
    private int direction = 0;
    private int speed = 2;
    boolean isLive = true;
    public void setShot(int x , int y , int direction){
        this.x=x;
        this.y=y;
        this.direction=direction;
    }
    public int getX(){
        return x;
    }
    public int getY(){
        return y;
    }public int getDirection(){
        return direction;
    }
    public int getSpeed(){
        return speed;
    }
    public void moveUp(){
        y -= speed;
    }
    public void moveRight(){
        x += speed;
    }
    public void moveDown(){
        y += speed;
    }
    public void moveLeft(){
        x -= speed;
    }
    @Override
    public void run() {
        while (true){
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            switch (getDirection()){
                case 0:
                    moveUp();
                    break;
                case 1:
                    moveRight();
                    break;
                case 2:
                    moveDown();
                    break;
                case 3:
                    moveLeft();
                    break;
            }
            if(!(x>=0 && x<=1000 && y>=0 && y<=750)){
                isLive = false;
                break;
            }
        }
    }
}
